package Cookie;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
/*  new Cookie("key","value")   ----  创建Cookie，键值对的方式存储
*   response.addCookie(cookie); ----  响应前端Cookie
*   request.getCookies();       ----  获取前端Cookie数组
*   Cookie.getPath();           ----  获取Cookie的路径
*   Cookie.setPath("/");        ----  设置Cookie的路径
*               请求路径和Cookie路径一致或者是其子路径，才会携带Cookie
*   Cookie.setMaxAge(int seconds); ---- 设置Cookie的有效期，设置以后直接按系统时间计算，单位是秒
*                                        到时自动消失，不会由浏览器决定
*                                         将生命周期设置成0就代表立即消失
* */
@WebServlet(value = "/Cookie/demo01")
public class CookieDemo01 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Cookie cookie = new Cookie("key", "value");
        response.addCookie(cookie);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
